// admin.js
const headerHTML = `
    <nav>
        <a href="index.html"> 首页</a>
        <a href="user-list.html"> 用户列表</a>
        <span id="user-info"></span>
        <button id="theme-toggle">切换主题</button>
    </nav>
`;

document.addEventListener('DOMContentLoaded', () => {
    let currentUser = JSON.parse(localStorage.getItem('admin')); 
    
    const headerContainer = document.createElement('div');
    headerContainer.innerHTML = headerHTML;
    document.body.insertBefore(headerContainer, document.body.firstChild);

    const userInfoElement = document.getElementById('user-info'); 
    
    if (currentUser) {
        userInfoElement.innerHTML = `
            <div class="dropdown">
                <img src="${currentUser.avatar || 'default-avatar.png'}" alt="用户头像" width="30" height="30">
                <span>${currentUser.username} (${currentUser.role === 'root' ? '超级管理员' : '普通用户'})</span> 
                <div class="dropdown-content">
                    ${currentUser.role === 'root' ? '<a href="admin.html">仪表盘</a>' : ''}
                    <a href="/profile.html" id="profile-link">个人资料</a>
                    <a href="/" id="logout-link">退出登录</a>
                </div>
            </div>
        `;
    }

    
});